/*
 * Copyright (C) 2021 NaviTech
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     core_internal
 * @{
 *
  * @file         base_types.h
  * @brief        通过将不同的模块的错误码分段，在得到错误码之后，可以快速分析出返回错误的模块以及原因。
  * @note
  * @author       lixinliang
  * @date         2021-08-14
  *
  * @par          修改日志
  * <table>
  * <tr><th>Date        <th>Version          <th>Author                        <th>Description
  * <tr><td>2021-08-14  <td>1.0              <td>lixinliang@hopechart.com      <td>创建初始版本
  * @copyright
  */

#ifndef _BASE_ERRORS_H_
#define _BASE_ERRORS_H_

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef int32_t TSFCErrors;

/**
 * @brief Sector0禁止使用，系统保留内部使用
 */
#define SFC_ERR_SEC_BASE00           ((int32_t)0x00000)

/**
 * @brief Definition of error code
 */
enum
{
    kSFCErrOk                  =  ((int32_t)0),
    kSFCErrFail                = -((int32_t)1),
    kSFCErrNoMem               = -((int32_t)0x101),   /*!< Out of memory */
    kSFCErrInvaildArg          = -((int32_t)0x102),   /*!< Invalid argument */
    kSFCErrInvaildState        = -((int32_t)0x103),   /*!< Invalid state */
    kSFCErrInvaildSize         = -((int32_t)0x104),   /*!< Invalid size */
    kSFCErrNotFound            = -((int32_t)0x105),   /*!< Requested resource not found */
    kSFCErrNotSupported        = -((int32_t)0x106),   /*!< Operation or feature not supported */
    kSFCErrTimeout             = -((int32_t)0x107),   /*!< Operation timed out */
    kSFCErrInvalidResponse     = -((int32_t)0x108),   /*!< Received response was invalid */
    kSFCErrInvalidCrc          = -((int32_t)0x109),   /*!< CRC or checksum was invalid */
    kSFCErrInvalidVersion      = -((int32_t)0x10A),   /*!< Version was invalid */
    kSFCErrInvalidAuth         = -((int32_t)0x10B),   /*!< Invalid auth, Password is invalid */
    kSFCErrOutofRange          = -((int32_t)0x10C),   /*!< 超出范围 */
};

#define SFC_ERR_SEC_BASE01           ((int32_t)0x01000) /*!< Starting number of Sector1 error codes */
#define SFC_ERR_SEC_BASE02           ((int32_t)0x02000) /*!< Starting number of Sector2 error codes */
#define SFC_ERR_SEC_BASE03           ((int32_t)0x03000) /*!< Starting number of Sector3 error codes */
#define SFC_ERR_SEC_BASE04           ((int32_t)0x04000) /*!< Starting number of Sector4 error codes */
#define SFC_ERR_SEC_BASE05           ((int32_t)0x05000) /*!< Starting number of Sector5 error codes */
#define SFC_ERR_SEC_BASE06           ((int32_t)0x06000) /*!< Starting number of Sector6 error codes */
#define SFC_ERR_SEC_BASE07           ((int32_t)0x07000) /*!< Starting number of Sector7 error codes */
#define SFC_ERR_SEC_BASE08           ((int32_t)0x08000) /*!< Starting number of Sector8 error codes */
#define SFC_ERR_SEC_BASE09           ((int32_t)0x09000) /*!< Starting number of Sector9 error codes */
#define SFC_ERR_SEC_BASE10           ((int32_t)0x0A000) /*!< Starting number of Sector10 error codes */
#define SFC_ERR_SEC_BASE11           ((int32_t)0x0B000) /*!< Starting number of Sector11 error codes */
#define SFC_ERR_SEC_BASE12           ((int32_t)0x0C000) /*!< Starting number of Sector12 error codes */
#define SFC_ERR_SEC_BASE13           ((int32_t)0x0D000) /*!< Starting number of Sector13 error codes */
#define SFC_ERR_SEC_BASE14           ((int32_t)0x0E000) /*!< Starting number of Sector14 error codes */
#define SFC_ERR_SEC_BASE15           ((int32_t)0x0F000) /*!< Starting number of Sector15 error codes */
#define SFC_ERR_SEC_BASE16           ((int32_t)0x10000) /*!< Starting number of Sector16 error codes */
#define SFC_ERR_SEC_BASE17           ((int32_t)0x11000) /*!< Starting number of Sector17 error codes */
#define SFC_ERR_SEC_BASE18           ((int32_t)0x12000) /*!< Starting number of Sector18 error codes */
#define SFC_ERR_SEC_BASE19           ((int32_t)0x13000) /*!< Starting number of Sector19 error codes */
#define SFC_ERR_SEC_BASE20           ((int32_t)0x14000) /*!< Starting number of Sector20 error codes */
#define SFC_ERR_SEC_BASE21           ((int32_t)0x15000) /*!< Starting number of Sector21 error codes */
#define SFC_ERR_SEC_BASE22           ((int32_t)0x16000) /*!< Starting number of Sector22 error codes */
#define SFC_ERR_SEC_BASE23           ((int32_t)0x17000) /*!< Starting number of Sector23 error codes */
#define SFC_ERR_SEC_BASE24           ((int32_t)0x18000) /*!< Starting number of Sector24 error codes */
#define SFC_ERR_SEC_BASE25           ((int32_t)0x19000) /*!< Starting number of Sector25 error codes */
#define SFC_ERR_SEC_BASE26           ((int32_t)0x1A000) /*!< Starting number of Sector26 error codes */
#define SFC_ERR_SEC_BASE27           ((int32_t)0x1B000) /*!< Starting number of Sector27 error codes */
#define SFC_ERR_SEC_BASE28           ((int32_t)0x1C000) /*!< Starting number of Sector28 error codes */
#define SFC_ERR_SEC_BASE29           ((int32_t)0x1D000) /*!< Starting number of Sector29 error codes */
#define SFC_ERR_SEC_BASE30           ((int32_t)0x1E000) /*!< Starting number of Sector30 error codes */
#define SFC_ERR_SEC_BASE31           ((int32_t)0x1F000) /*!< Starting number of Sector31 error codes */
#define SFC_ERR_SEC_BASE32           ((int32_t)0x20000) /*!< Starting number of Sector32 error codes */

// example:
// #define FLASH_ERR_SEC SFC_ERR_SEC_BASE1 // 定义 FLASH 错误的起始值
// MAKE_ERROR_CODE(FLASH_ERR_SEC, 1)
// #define RTC_ERR_SEC   SFC_ERR_SEC_BASE2 // 定义 RTC 错误的起始值
// MAKE_ERROR_CODE(RTC_ERR_SEC, 1)
#define MAKE_ERROR_CODE(sector, code) (0x80000000 | (sector) | ((code) & 0xFFF))

#ifdef __cplusplus
} // extern "C" {
#endif

#endif	// _BASE_TYPES_H_
/** @} */
